import { Injectable } from '@nestjs/common';
import { FindOneOptions, Repository } from 'typeorm';
import { DeepPartial } from 'typeorm/common/DeepPartial';
import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity';
@Injectable()
export abstract class MySQLBaseService<T> {
  constructor(protected repository: Repository<T>) {}

  async findAll() {
    return this.repository.find();
  }
  async findOne(options: FindOneOptions) {
    return this.repository.findOne(options);
  }
  async create(createDto: DeepPartial<T>) {
    return  this.repository.save(createDto);
  }
  async update(id: number, updateDto: QueryDeepPartialEntity<T>) {
    return this.repository.update(id, updateDto);
  }
  async delete(id: number) {
    return this.repository.delete(id);
  }
}
